package com.coderlin1.service.impl;

import com.coderlin1.entities.Customer;
import com.coderlin1.mapper.CustomerMapper;
import com.coderlin1.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <Description> <br>
 *
 * @author Coder_Lin<br>
 * @version 1.0<br>
 * @taskId: <br>
 * @createDate 2021/07/30 9:48 <br>
 * @see com.coderlin1.service.impl <br>
 */
@Service
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    private CustomerMapper customerMapper;
    /**
     * 列出所有的customer
     *
     * @return
     */
    @Override
    public List<Customer> listCustomer() {
        return customerMapper.listCustomer();
    }

    /**
     * 添加用户
     *
     * @param custName
     * @param custMobile
     * @param custAddress
     * @param custTicket
     * @return
     */
    @Override
    public Integer addCustomer(String custName, String custMobile, String custAddress, Integer custTicket) {
        Customer customer = new Customer(0, custName, custMobile, custAddress, custTicket);

        return customerMapper.addCustomer(customer);
    }

    /**
     * 根据输入的文本进行模糊查询
     *
     * @param custName
     * @return
     */
    @Override
    public List<Customer> searchCustomerByName(String custName) {
        return customerMapper.searchCustomerByName(custName);
    }

    /**
     * 根据id查询出用户信息
     *
     * @param cid
     * @return
     */
    @Override
    public Customer listCustomerById(Integer cid) {
        return customerMapper.listCustomerById(cid);
    }

    /**
     * 修改用户信息，并对controller层转发的数据进行封装
     *
     * @param cid
     * @param custName
     * @param custMobile
     * @param custAddress
     * @param custTicket
     * @return
     */
    @Override
    public Integer modCustomer(Integer cid, String custName, String custMobile, String custAddress, Integer custTicket) {
        Customer customer = new Customer(cid, custName, custMobile, custAddress, custTicket);

        return customerMapper.modCustomer(customer);
    }

    /**
     * 根据id删除客户信息
     *
     * @param cid
     * @return
     */
    @Override
    public Integer delCustomer(Integer cid) {
        return customerMapper.delCustomer(cid);
    }
}
